#import "YQOrderLogisticsWriteVC.h"

#import "YQGoodsOrderDetailsVC.h"
#import "YQOrderDetailsHeaderView.h"
#import "YQOrderDetailsBottonView.h"
#import "OrderEvaViewController.h"
#import "YQGoodsOrderModel.h"
#import "YQOrderRefundShowView.h"
#import "YQOrderRefundVC.h"
#import "YQGoodsOrderDetailsModel.h"
#import "YQGoodsOrderModel.h"
#import "YQPOrderModel.h"
#import <AlipaySDK/AlipaySDK.h>
#import <WXApi.h>
@interface YQGoodsOrderDetailsVC ()<YQOrderDetailsBottonViewDelegate,YQOrderManageGoodsCellDelegate>

@property (nonatomic, strong) YQOrderDetailsHeaderView * headerView;
@property (nonatomic, strong) YQOrderDetailsBottonView * bottonView;
@property (nonatomic, strong) YQGoodsOrderDetailsModel * orderDetailsModel;
@property (nonatomic, assign) NSInteger section;
@property (nonatomic, copy) NSArray * orderDetailsTitleArr;
@property (nonatomic,retain) NSMutableDictionary *payParameters;
@property (nonatomic,retain) NSTimer *timer;
@end

@implementation YQGoodsOrderDetailsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = kYQLS(@"订单详情");
    UIImage *rightImage = YQIMG(@"MY_nav_service_icon");
    self.rightItemImage = [rightImage qmui_imageWithTintColor:UIColor.whiteColor];
    self.orderDetailsTitleArr = @[[NSString stringWithFormat:@"%@ :",kYQLS(@"订单编号")],[NSString stringWithFormat:@"%@ :",kYQLS(@"订单创建时间")],[NSString stringWithFormat:@"%@ :",kYQLS(@"支付时间")],[NSString stringWithFormat:@"%@ :",kYQLS(@"发货时间")],kYQLS(@"确认收货时间")];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(paySucceedAction) name:YJPaySucceedNotiKey object:nil];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self getDetailsData];

}

-(void)setupView {
    [super setupView];
    [self _setupNav];
    UIImage *leftImage = YQIMG(@"nav_back_sIcon");
    [self.leftItem setImage:[leftImage qmui_imageWithTintColor:UIColor.whiteColor] forState:(UIControlStateNormal)];
    [self.view addSubview:self.headerView];
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(154);
    }];
    self.listTableView.backgroundColor = HexColor(0xFAFAFA);
    self.listTableView.frame = CGRectMake(0, 154, kYQPScreenWidth, kYQPScreenHeight-Height_NavBar-kHeight_Botton_SafeArea-154);
//    [self.view addSubview:self.bottonView];
//    [self.bottonView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.mas_equalTo(0);
//        make.left.mas_equalTo(0);
//        make.right.mas_equalTo(0);
//        make.height.mas_equalTo(49);
//    }];
    kYQREGISTERTABLEVIEWNIBCELL(@"YQOrderManageGoodsCell")
    kYQREGISTERTABLEVIEWNIBCELL(@"YQOrderDetailsMoneyCell")
    kYQREGISTERTABLEVIEWNIBCELL(@"YQOrderDetailsLookLogisticsCell")
    kYQREGISTERTABLEVIEWNIBCELL(@"YQOrderDetailsInfoCell")
//    kYQREGISTERTABLEVIEWNIBCELL(@"YQOrderManageBtnActionCell")
    kYQREGISTERTABLEVIEWCHeaderFooter([YQOrderDetailsTitleHeader class])
    self.listTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self getDetailsData];
    }];
}

-(void)rightItemAction:(UIButton *)sender {
    
}

#pragma mark - 获取订单详情接口
-(void)getDetailsData {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"orderId"] = self.OrderModel.orderId;
    parameters[@"orderType"] = @(self.OrderModel.orderType);
    
    YQSHOWLOADINGINVIEW
    [YQPNetWorkingManager sendPostRequest:kPOST_GOODS_ORDER_INFO_URL parameters:parameters success:^(YQPNetWorkingBaseModel * _Nonnull responseObject) {
        [self stopRefresh];
        YQHIDELOADINGTIPS
        if (responseObject.code == 0) {
            self.orderDetailsModel = [YQGoodsOrderDetailsModel modelWithJSON:responseObject.data];
            self.headerView.orderDetailsModel = self.orderDetailsModel;
            self.bottonView.orderDetailsModel = self.orderDetailsModel;//决定详情页面底部按钮的字样显示
            if (self.orderDetailsModel.orderStatus == 301 || self.orderDetailsModel.orderStatus == 302 || self.orderDetailsModel.orderStatus == 303) {
                self.section = 4;
            }else{
                self.section = 3;
            }
            
            [self.listTableView reloadData];
        }else{
            YQUITIPSERROR(responseObject.msg)
        }
    } failure:^(NSUInteger statusCode, NSString * _Nonnull error) {
        YQHIDELOADINGTIPS
        YQUITIPSERROR(error)
        [self stopRefresh];
    }];
    
}

#pragma makr -- lazy
-(YQOrderDetailsHeaderView *)headerView {
    if (!_headerView) {
        _headerView = [YQOrderDetailsHeaderView viewFromXib];
        _headerView.topBgView.backgroundColor = kAPPThemeColor;
    }
    return _headerView;
}

-(YQOrderDetailsBottonView *)bottonView {
    if (!_bottonView) {
        _bottonView = [YQOrderDetailsBottonView viewFromXib];
        _bottonView.backgroundColor = UIColor.whiteColor;
        //2.设置阴影偏移范围
        _bottonView.layer.shadowOffset = CGSizeMake(0, 2);
        //3.设置阴影颜色的透明度
        _bottonView.layer.shadowOpacity = 0.5;
        
        //4.设置阴影半径
        _bottonView.layer.shadowRadius = 4;
        //5.设置阴影路径
        _bottonView.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.navigationController.navigationBar.bounds].CGPath;
        [_bottonView.rightBtn setTitle:kYQLS(@"评价") forState:(UIControlStateNormal)];
        _bottonView.delegate = self;
//        ws(self);
//        [_bottonView.rightBtn addTapAction:^(id  _Nonnull sender) {
//            OrderEvaViewController *VC = [[OrderEvaViewController alloc] init];
//            [weakself.navigationController pushViewController:VC animated:true];
//        }];
    }
    return _bottonView;
}

#pragma makr -- lazy end
#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.section;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if(section == 1){
        return 4;
    }else if (section == 0) {
        return self.orderDetailsModel.orderItemList.count;
    }else if(section == self.section-1) {
        return 5;
    }
    return 1;
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    if (indexPath.section == 0) {//每个商品cell底部加一行售后按钮
        YQGoodsOrderItemModel *goodsModel = nil;
        if (indexPath.row < self.orderDetailsModel.orderItemList.count) {
            goodsModel = self.orderDetailsModel.orderItemList[indexPath.row];
        }

        YQOrderManageGoodsCell *goodsCell = [tableView dequeueReusableCellWithIdentifier:@"YQOrderManageGoodsCell"];
        goodsCell.goodsModel = goodsModel;
        [goodsCell setRefunDetailModel:self.orderDetailsModel :indexPath];
        goodsCell.delegate = self;
        return goodsCell;
        
    }else if (indexPath.section == 1) {
        YQOrderDetailsMoneyCell *moneyCell = [tableView dequeueReusableCellWithIdentifier:@"YQOrderDetailsMoneyCell"];
        if (indexPath.row == 0) {
            moneyCell.labTitle.text = kYQLS(@"运费");
            moneyCell.labSubTitle.text = [NSString stringWithFormat:@"HKD%@",self.orderDetailsModel.freightAmount];
        }else if(indexPath.row == 1){
            moneyCell.labTitle.text = kYQLS(@"运费险");
            moneyCell.labSubTitle.text = @"HKD0";//[NSString stringWithFormat:@"￥%@",self.orderDetailsModel.freightAmount];
        }else if (indexPath.row == 2) {
            moneyCell.labTitle.text = kYQLS(@"积分抵扣");
            if ([self.orderDetailsModel.integrationAmount integerValue] == 0) {
                moneyCell.labSubTitle.text = @"HKD0";
            }else{
                moneyCell.labSubTitle.text = [NSString stringWithFormat:@"-HKD%@",self.orderDetailsModel.integrationAmount];
            }
            
        }else{
            moneyCell.labTitle.text = kYQLS(@"订单实付款");
            moneyCell.labSubTitle.text = [NSString stringWithFormat:@"HKD%@",self.orderDetailsModel.payAmount];
        }
        return moneyCell;
    }else if (indexPath.section == self.section-1) {
        YQOrderDetailsInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YQOrderDetailsInfoCell"];
        cell.titleLb.text = self.orderDetailsTitleArr[indexPath.row];
        cell.infoLb.text = kYQLS(@"未创建");
        if (indexPath.row == 0) {
            cell.infoLb.text = self.orderDetailsModel.orderSn;
        }else if (indexPath.row == 1) {
            cell.infoLb.text = [NSDate getDateToTime:[self.orderDetailsModel.createTime doubleValue] format:@"yyyy-MM-dd"];
        }else if(indexPath.row == 2) {
            cell.infoLb.text = [NSDate getDateToTime:[self.orderDetailsModel.paymentTime doubleValue] format:@"yyyy-MM-dd"];//[self.orderDetailsModel.paymentTime removeStringSpace].length >0 ? self.orderDetailsModel.paymentTime : @"未创建";
        }else if (indexPath.row == 3) {
            cell.infoLb.text = [NSDate getDateToTime:[self.orderDetailsModel.deliveryTime doubleValue] format:@"yyyy-MM-dd"];//[self.orderDetailsModel.deliveryTime removeStringSpace].length > 0 ? self.orderDetailsModel.deliveryTime : @"未创建";;
        }else{
            cell.infoLb.text = [NSDate getDateToTime:[self.orderDetailsModel.receiveTime doubleValue] format:@"yyyy-MM-dd"];//[self.orderDetailsModel.receiveTime removeStringSpace].length > 0 ? self.orderDetailsModel.receiveTime : @"未创建";;
        }
        return cell;
    }
    
    YQOrderDetailsLookLogisticsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YQOrderDetailsLookLogisticsCell"];
    return cell;

}

#pragma mark - YQOrderManageGoodsCellDelegate 点击售后按钮
- (void)selectGoodItemModel:(YQGoodsOrderItemModel *)model
{
    if ([model.refundStatus isEqualToString:@"4"]) {//填写物流
        YQOrderLogisticsWriteVC *writeVC = [[YQOrderLogisticsWriteVC alloc] init];
        writeVC.model = model;
        writeVC.detailModel = self.orderDetailsModel;

        [self.navigationController pushViewController:writeVC animated:true];
    }else{
        [self afterSaleAction:model];
    }
}

#pragma mark - 撤销
- (void)selectCancelGoodItemModel:(YQGoodsOrderItemModel *)model
{
    NSMutableDictionary *params = NSMutableDictionary.new;
    params[@"refundId"] = @"0";
    params[@"orderItemId"] = model.orderItemId;
    params[@"orderType"] = @(self.orderDetailsModel.orderType);

    YQSHOWLOADINGINVIEW
    [YQPNetWorkingManager sendPostRequest:kPOST_REFUND_CANCEL_URL parameters:params success:^(YQPNetWorkingBaseModel * _Nonnull responseObject) {
        [self stopRefresh];
        YQHIDELOADINGTIPS
        if (responseObject.code == 0) {
            kMBMesHUD(kYQLS(@"撤销成功"));
            [self getDetailsData];
        }else{
            YQUITIPSERROR(responseObject.msg)
        }
    } failure:^(NSUInteger statusCode, NSString * _Nonnull error) {
        YQHIDELOADINGTIPS
        [self stopRefresh];
    }];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        
        return 104 + 50;
    }else if (indexPath.section == 1){
        return 30;
    }else if (indexPath.section == self.section-1) {
        return 21;
    }
    return 44;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    if (section == 0) {
        UIView *view = [UIView new];
        view.backgroundColor = UIColor.whiteColor;
        return view;
    }
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (section == 0) {
        return 23.5;
    }
    return 10;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == self.section-1) {
        YQOrderDetailsTitleHeader *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"YQOrderDetailsTitleHeader"];
        return header;
    }
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == self.section-1) {
        return 39;
    }
    return 0.001;
}
#pragma mark - UITableViewDelegate, UITableViewDataSource end

#pragma -mark 私有
-(void)_setupNav {
    UIFont *font = kSystemMedium(17);
    NSDictionary *dic = @{ NSFontAttributeName:font,NSForegroundColorAttributeName:UIColor.whiteColor};
    self.navigationController.navigationBar.titleTextAttributes =dic;
    // 一行代码搞定导航栏颜色
    [self wr_setNavBarBarTintColor:kAPPThemeColor];
    // 一行代码搞定导航栏底部分割线是否隐藏
    [self wr_setNavBarShadowImageHidden:YES];
    [self wr_setNavBarTitleColor:[UIColor whiteColor]];
    [self wr_setNavBarTintColor:UIColor.whiteColor];
}

- (void)selectItem:(NSInteger)itme {
        switch (self.orderDetailsModel.orderStatus) {
            case 101:
                if (itme == 0) {
                    QMUIAlertController *alert = [[QMUIAlertController alloc] initWithTitle:kYQLS(@"确定取消该订单?") message:@"" preferredStyle:(QMUIAlertControllerStyleAlert)];
                    
                    [alert addAction:[QMUIAlertAction actionWithTitle:kYQLS(@"我再想一想") style:(QMUIAlertActionStyleCancel) handler:^(__kindof QMUIAlertController * _Nonnull aAlertController, QMUIAlertAction * _Nonnull action) {
                        
                    }]];
                    alert.alertCancelButtonAttributes = @{NSForegroundColorAttributeName:kAPPThemeColor,NSFontAttributeName:UIFontBoldMake(17),NSKernAttributeName:@(0)};
                    
                    [alert addAction:[QMUIAlertAction actionWithTitle:kYQLS(@"确定") style:(QMUIAlertActionStyleDefault) handler:^(__kindof QMUIAlertController * _Nonnull aAlertController, QMUIAlertAction * _Nonnull action) {
                        //取消订单
                        [self cancelActionOrder];
                    }]];
                    alert.alertButtonAttributes = @{NSForegroundColorAttributeName:HexColor(0xB7B7B7),NSFontAttributeName:kSystemMedium(17),NSKernAttributeName:@(0)};
                    
                    [alert showWithAnimated:YES];
                }else{
                    //立即支付
                    [MYShopSalesOrderPayView shopSalesOrderPayView:[NSString stringWithFormat:@"%@",self.orderDetailsModel.payAmount] :^(NSInteger index, NSString * typeStr) {
                        [self getOrderPayType:index orderId:self.orderDetailsModel.orderId];
                    } :^{
                        NSLog(@"");
                    }];
                }
                break;
            case 102 | 103:
                [self deleteOrderAction];
                break;
            case 202:
                [self deleteOrderAction];
                break;
            case 201:
//                if (itme == 0) {
                [self afterSaleAction:self.orderDetailsModel];
//                }else{
//                    //"等待卖家发货"
//                    [self cancelActionOrder];
//                }
                break;
            case 301:
                //"卖家已发货"
                if (itme == 0) {
                    [self afterSaleAction:self.orderDetailsModel];
                }else{
                    [self confirmOrderAction];
                }
                break;
            case 302:
            case 303:
                //"交易成功";
//                [self.leftBtn setTitle:@"删除订单" forState:UIControlStateNormal];
//                [self.rightBtn setTitle:@"发布评价" forState:UIControlStateNormal];
                if (itme == 0) {
//                    [self deleteOrderAction];
                    [self afterSaleAction:self.orderDetailsModel];
                }else{
                    if (self.OrderModel.commentType == 0) {
                        OrderEvaViewController *VC = [[OrderEvaViewController alloc] init];
                        VC.orderModel = self.OrderModel;
                        [self.navigationController pushViewController:VC animated:true];
                    }
                }
                    
                
                break;
                
            default:
                break;
        }
}
//售后
-(void)afterSaleAction:(YQGoodsOrderItemModel *)model{
    
    [YQOrderRefundShowView refundShowViewViewResultBlack:^(NSInteger row) {
        YQOrderRefundVC *refundVC = [[YQOrderRefundVC alloc] init];
        refundVC.type = row;//
        refundVC.OrderModel = model;
        refundVC.detailModel = self.orderDetailsModel;
        ws(self);
        refundVC.ssucceeBlock = ^{
//            [weakself getDetailsData];
        };
        [weakself.navigationController pushViewController:refundVC animated:true];
    }];
}

//确认收货
-(void)confirmOrderAction {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
      parameters[@"orderType"] = @(self.orderDetailsModel.orderType);
      parameters[@"orderId"] = self.orderDetailsModel.orderId;
      YQSHOWLOADINGINVIEW;
      [YQPNetWorkingManager sendPostRequest:kPOST_RECEIVE_GOODS_URL parameters:parameters success:^(YQPNetWorkingBaseModel * _Nonnull responseObject) {
          YQHIDELOADINGTIPS
          if (responseObject.code == 0) {
              YQUITIPSSUCCEED(responseObject.msg)
              [self getDetailsData];
          }else{
              YQUITIPSERROR(responseObject.msg)
          }
          
      } failure:^(NSUInteger statusCode, NSString * _Nonnull error) {
          YQHIDELOADINGTIPS
      }];
}
//删除订单
-(void)deleteOrderAction {

    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"orderType"] = @(self.orderDetailsModel.orderType);
    parameters[@"orderId"] = self.orderDetailsModel.orderId;
    YQSHOWLOADINGINVIEW;
    [YQPNetWorkingManager sendPostRequest:kPOST_BASE_ORDER_DELETE_URL parameters:parameters success:^(YQPNetWorkingBaseModel * _Nonnull responseObject) {
        YQHIDELOADINGTIPS
        if (responseObject.code == 0) {
            YQUITIPSSUCCEED(responseObject.msg)
            [self.navigationController popViewControllerAnimated:true];
        }else{
            YQUITIPSERROR(responseObject.msg)
        }
        
    } failure:^(NSUInteger statusCode, NSString * _Nonnull error) {
        YQHIDELOADINGTIPS
    }];
}
//取消订单
-(void)cancelActionOrder{
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"cancelOrderContent"] = @"";
    parameters[@"orderId"] = self.orderDetailsModel.orderId;
    parameters[@"orderType"] = @(self.orderDetailsModel.orderType);
    YQSHOWLOADINGINVIEW;
    [YQPNetWorkingManager sendPostRequest:kPOST_GOODS_ORDER_cancel_URL parameters:parameters success:^(YQPNetWorkingBaseModel * _Nonnull responseObject) {
        YQHIDELOADINGTIPS
        if (responseObject.code == 0) {
            YQUITIPSSUCCEED(responseObject.msg)
            [self getDetailsData];
        }else{
            YQUITIPSERROR(responseObject.msg)
        }
        
    } failure:^(NSUInteger statusCode, NSString * _Nonnull error) {
        YQHIDELOADINGTIPS
    }];
}
//支付
-(void)getOrderPayType:(NSInteger)type orderId:(NSString *)orderId {
    NSMutableDictionary *par = @{}.mutableCopy;
    par[@"orderId"] = orderId;
    par[@"payType"] = @(type + 1);
    par[@"orderType"] = @"1";
    self.payParameters=par;
    NSString *url=kALIPAY_ALIPAYPAYREQUEST_URL;
          if (type==1)
          {
              url=kALIPAY_WECHATPAYPAYREQUEST_URL;
          }
    [YQPNetWorkingManager sendPostRequest:url parameters:par success:^(YQPNetWorkingBaseModel * _Nonnull responseObject) {
        if (responseObject.code == 0) {
           if (type == 0) {
                [self goToAlipayData:responseObject.data];
            }
            else
            {
                NSDictionary *dict=(NSDictionary*)responseObject.data;
                PayReq* req= [[PayReq alloc] init];
                req.openID=[dict objectForKey:@"appId"];
                req.partnerId= [dict objectForKey:@"partnerId"];
                req.prepayId= [dict objectForKey:@"prepayId"];
                req.nonceStr = [dict objectForKey:@"nonceStr"];
                req.timeStamp= [[dict objectForKey:@"timestamp"] intValue];
                req.package= [dict objectForKey:@"packageStr"];
                req.sign= [dict objectForKey:@"sign"];
                [WXApi sendReq:req completion:^(BOOL success) {
                    NSLog(@"1");
                }];
            }
        }else{
            YQUITIPSERROR(responseObject.msg)
        }
    } failure:^(NSUInteger statusCode, NSString * _Nonnull error) {
        YQUITIPSERROR(error)
    }];
}
-(void)goToAlipayData:(NSString *)dataStr{
    NSString *appScheme = @"com.MuYing.www";
    [[AlipaySDK defaultService] payOrder:dataStr fromScheme:appScheme callback:^(NSDictionary *resultDic) {
        //网页支付回调
        NSNotificationCenter *notiCenter=[NSNotificationCenter defaultCenter];
        //NSLog(@"result = %@",resultDic);
        NSString *resultStatus = resultDic[@"resultStatus"];
        if ([resultDic[@"memo"] isEqualToString:@""] && [resultStatus isEqualToString:@"9000"]) {
            /*支付成功通知*/
            [notiCenter postNotificationName:YJPaySucceedNotiKey object:self userInfo:nil];
        }else{
            
            if ([resultStatus isEqualToString:@"6001"]) {
                /*用户取消了支付*/
                dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC));
                dispatch_after(delayTime, dispatch_get_main_queue(), ^{
                    MBErrHUD(kYQLS(@"支付已取消"));
                });
            }else{
                NSString * strMsg = [NSString stringWithFormat:@"%@：%@,%@",kYQLS(@"支付结果"),kYQLS(@"支付失败"),resultDic[@"memo"]];
                NSLog(@"strMsg: %@",strMsg);
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:strMsg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                [alert show];
            }
            
        }
    }];
}

-(void)paySucceedAction
{
   YQSHOWLOADINGINVIEW
   self.timer=[NSTimer scheduledTimerWithTimeInterval:2  target:self  selector:@selector(verifyPaymentResults) userInfo:nil  repeats:YES];
}

- (void)verifyPaymentResults
{
    [YQPNetWorkingManager sendPostRequest:kPAYRETURN parameters:self.payParameters success:^(YQPNetWorkingBaseModel * _Nonnull responseObject) {
        if (responseObject.code == 0) {
            YQHIDELOADINGTIPS
            [self.timer invalidate];
            self.timer=nil;
            MYShopSalesOrderSucceedVC *succeedVC = [[MYShopSalesOrderSucceedVC alloc]initWithNibName:@"MYShopSalesOrderSucceedVC" bundle:nil];
            succeedVC.isIntegral = NO;
            succeedVC.navigationItem.title = kYQLS(@"支付成功");
            succeedVC.paySuceedLb.text = kYQLS(@"订单支付成功");
            succeedVC.paySuceedBtnText = kYQLS(@"查看我的订单");
            [self.navigationController pushViewController:succeedVC animated:true];
        }
        else if (responseObject.code==4) {
        }
        else
        {
                YQHIDELOADINGTIPS
                [self.timer invalidate];
                self.timer=nil;
                YQUITIPSERROR(responseObject.msg);
        }
    } failure:^(NSUInteger statusCode, NSString * _Nonnull error) {
        YQHIDELOADINGTIPS
        YQUITIPSERROR(error)
        [self.timer invalidate];
        self.timer=nil;
    }];
}

-(void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
